﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace SqlBlocks.Gui
{
    [Serializable]
    public class Settings
    {
        public string LastDirectory { get; set; }

        public static Settings Current { get; private set; }

        static Settings()
        {
            var file = new FileInfo(Path.Combine(Utility.UserDataDirectory, "Settings.crap"));

            Settings settings = null;

            if (file.Exists)
            {
                using (var stream = File.OpenRead(file.FullName))
                {
                    var formatter = new BinaryFormatter();

                    settings = formatter.Deserialize(stream) as Settings;
                }
            }

            Current = settings ?? new Settings();
        }

        public static void Save()
        {
            var file = new FileInfo(Path.Combine(Utility.UserDataDirectory, "Settings.crap"));

            using (var stream = File.OpenWrite(file.FullName))
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, Current);
            }
        }
    }
}
